<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="/js/jquery-1.7.2.min.js"></script>
</head>

<body style="font-family:Arial, Helvetica, sans-serif">
<h1>Customer Picking Up Wizard <br />
  Step 1</h1>
<p>
  <br />
  1) Filling the missing information<br />
</p>
<form id="form1" name="form1" method="post" action="/repaircenter/device-pickup-warranty/idjob/<?php echo $this->idJob?>/shop/<?php echo $this->shopCode?>/idrc/<?php echo $this->idRcenter?>">
<table width="800" border="1" cellspacing="0" cellpadding="10">
  <tr>
    <th scope="col" width="400" >All Mobiles include iPhone<br /></th>
    <th scope="col">iPad  / iTouch Device ID<br /></th>
  </tr>
  <tr>
    <th scope="col" >Key *#06# On The Dial Pad, <br />
    15 Digits , Number only</th>
    <th scope="col">At The Back of the Device, <br />
    12 Digits, Letter &amp; Number</th>
  </tr>
  <tr>
    <td align="center">
    <input name="mobile_imei" type="text" id="mobile_imei" value="<?php echo $this->mobile_imei; ?>" /></td>
    <td align="center"><input name="mobile_aid" type="text" id="mobile_aid" value="<?php echo $this->mobile_aid; ?>" /></td>
  </tr>
  <tr>
    <td colspan="2" align="center"><span id="imei_result"></span></td>
  </tr>
</table>
<p>
  <br />
  <br />
  2) Check the Quotation, Payment and APOS Invoice<br />
  <br />
</p>
<table width="800" border="1" cellspacing="0" cellpadding="10">
  <tr>
    <td  style="padding:10px; border: #960 2px solid; background-color:#FF9;" >Please let customer provide the &quot;Customer Copy of Repair Job Form&quot;<br />
      PLEASE CHECK:<br />
      1) 
      Total Quotation Amount, if the amount is reasonable (you may need to ask the repair technician)<br />
      2) Total Payment, APOS Invoice should exactly match with the quotation
      <br /></td>
  </tr>
</table>
<br />
<br />

<table width="800" border="1" cellspacing="0" cellpadding="10">
  <tr>
    <th colspan="4" align="left"  scope="col">Total Quote For the Job : $
      <label for="quote_job"></label>
    <input name="quote_job" type="text" id="quote_job" value="<?php echo $this->quotePrice?>" /> 
    + 
    Extended Warranty $ 
    <input name="ext_warranty" type="text" id="ext_warranty" value="<?php echo $this->extWPrice?>" /></th>
  </tr>
  <?php if(trim($this->inv1)=='' && trim($this->inv2)=='' ) {?>
  <tr>
    <th colspan="4" align="left" bgcolor="#FF6666" scope="col">We do not have any APOS Invoice recorded for this JOB, the service has been charged ?</th>
  </tr>
<?php } else{ ?>
  <tr>
    <th colspan="4" align="left" bgcolor="#33CC33" scope="col">We have following APOS Invoice(s) for this JOB, if you need to make any change, you may do it now</th>
  </tr>
<?php }?>  
  <tr>
    <td>APOS Invoice 1<span style="font-weight:bold;color:#F00;">*</span> </td>
    <td><input name="inv_no1" type="text" id="inv_no1" value="<?php echo $this->inv1?>" /></td>
    <td>APOS Invoice 2</td>
    <td><input name="inv_no2" type="text" id="inv_no2" value="<?php echo $this->inv2?>" /></td>
  </tr>
  <tr>
    <td align="right">$</td>
    <td><input type="text" name="inv_amt1" id="inv_amt1" value="<?php echo $this->inv1Amt; ?>"/></td>
    <td align="right">$</td>
    <td><input type="text" name="inv_amt2" id="inv_amt2" value="<?php echo $this->inv2Amt; ?>" /></td>
  </tr>
  <tr>
  <td colspan="4"><span id="matchresult"></span></td>
  </tr>
</table>
<p>3) Select Warranty Period <br />
  <br />
<table width="800" border="1" cellspacing="0" cellpadding="10">  
  <tr>
      <td colspan="2" align="center">The hardware (repair parts) warranty for this JOBID: <?php echo $this->idJob;?> is :</td>
    </tr>
    <tr>
      <td colspan="2" align="center"><label for="select">Warranty Period: <?php echo $this->warrantyPeriod; ?> Days</label></td>
    </tr>
    <tr>
      <td colspan="2" align="center"><label for="select3">Extended Warranty : <?php echo $this->extWarranty; ?> Days </label></td>
    </tr>
    <tr>
    <td colspan="2" align="center"><strong>Choose Warranty Expire Date For Print (MUST CHOOSE ONE)</strong></td>
  </tr>
  <tr>
    <td colspan="2" align="left"><input type="radio" name="warranty_confirm" id="warranty_confirm1" value="<?php echo $this->wyEnd;?>" />
      <label for="warranty_confirm"></label>
      This limited hardware warranty (excluded Water damage )will expire on 12pm of <?php echo $this->wyEnd;?></td>
  </tr>
  <tr>
    <td colspan="2" align="left"><input type="radio" name="warranty_confirm" id="warranty_confirm2" value="<?php echo $this->wrEnd;?>" />      
      Water Damage Warranty will expire on 12 pm of <?php echo $this->wrEnd;?></td>
  </tr>
  </table>
</p>

  <input type="submit" name="btn_next" id="btn_next" value="NEXT" style="font-size:28px;" />
</form>
<p><br />
</p>
</body>
<script type="text/javascript"> 

function checkTheIMEI(){
	
	var imeiCheckPass,aidCheckPass,imei,aid;
		imeiCheckPass = false;
		aidCheckPass = false;
		
					imei = $("#mobile_imei").val();
	aid = $("#mobile_aid").val();
	
		
	if(imei.length >0 ){
		aidCheckPass = true;
		
		imeiCheckPass =  isIMEI(imei);
		
		}
	if(aid.length > 0){
		imeiCheckPass = true;
		
		aidCheckPass = checkDeviceID(aid);
		
		}
	if(imei.length > 0 && aid.length >0 ){
		
		imeiCheckPass = false;
		aidCheckPass = false;

		}	
		
	if(imeiCheckPass && aidCheckPass){
		
		$("#imei_result").html("IMEI/Device ID Check Pass");
		}	
	else{
		$("#imei_result").html("Please Must Input Validated IMEI!!");
			if(imei.length > 0 && aid.length >0 ){
				$("#imei_result").html("<span style=\"color:#f00;\">You CANNOT Put Both IMEI and Device ID, Input ONE ONLY!</span>");
				$("#mobile_imei").val("");
				$("#mobile_aid").val("");
		}
		}	
				
	}

function checkMatch(){

		var qPrice,ePrice,inv1Amt,inv2Amt,inv1No,inv2No,inv1CheckPass,inv2CheckPass,matchCheckPass,imeiCheckPass,aidCheckPass,imei,aid,radioCheckPass;
		
		inv1CheckPass = false;
		inv2CheckPass = false;
		matchCheckPass = false;
		imeiCheckPass = false;
		aidCheckPass = false;
		radioCheckPass = false;
		
		
		
		inv1No = $("#inv_no1").val().toUpperCase();
		inv2No = $("#inv_no2").val().toUpperCase();
		
		qPrice = parseFloat(Number($("#quote_job").val()));
		ePrice = parseFloat(Number($("#ext_warranty").val()));
		inv1Amt = parseFloat(Number($("#inv_amt1").val()));
		inv2Amt = parseFloat(Number($("#inv_amt2").val()));
		
		
		
		
		
		if(inv1Amt >0.04 && inv1No.length == 10  && (inv1No.substring(0,1) == 'L' || inv1No.substring(0,1) == 'C')){
			inv1CheckPass = true;
			}
		else{
			inv1CheckPass = false;
			}	
		if(inv2Amt > 0.04){
			if(inv2No.length == 10  && (inv1No.substring(0,1) == 'L' || inv1No.substring(0,1) == 'C') ){
				inv2CheckPass = true;
				}
			else{
				inv2CheckPass = false;
				}	
			}
		else{
			inv2CheckPass = true;	
			}
		
		
		
		if(Math.abs(qPrice + ePrice - inv1Amt - inv2Amt) < 0.04 ){
			matchCheckPass = true;
			
			$("#matchresult").html("");

			}
		else{
			matchCheckPass = false;
			
			$("#matchresult").html("<span style=\"color:#f00;\">Total Invoice Amount Must Match Job Quotation + Extended Warranty</span> ");
			}		
		
		//alert(inv1CheckPass);
		//alert(inv2CheckPass);
		//alert(matchCheckPass);
			imei = $("#mobile_imei").val();
	aid = $("#mobile_aid").val();
	
	if(imei.length >0 ){
		aidCheckPass = true;
		
		imeiCheckPass =  isIMEI(imei);
		
		}
	if(aid.length > 0){
		imeiCheckPass = true;
		
		aidCheckPass = checkDeviceID(aid);
		
		}
	if(imei.length > 0 && aid.length >0 ){
		
		imeiCheckPass = false;
		aidCheckPass = false;
		}
	
	radioCheckPass = radioChecked();	

		if(inv1CheckPass && inv2CheckPass && matchCheckPass && imeiCheckPass && aidCheckPass && radioCheckPass){
			$("#btn_next").removeAttr("disabled");			
			}
		else{
			$("#btn_next").attr('disabled','disabled');			
			}	
		
		}
		
		
function isIMEI (s) {
var etal = /^[0-9]{15}$/;
  if (!etal.test(s))
    return false;
 
 var value = parseInt(s);
 if(value == 0){
	 return false;
	 }
 			
  sum = 0; mul = 2; l = 14;
  for (i = 0; i < l; i++) {
    digit = s.substring(l-i-1,l-i);
    tp = parseInt(digit,10)*mul;
    if (tp >= 10)
         sum += (tp % 10) +1;
    else
         sum += tp;
    if (mul == 1)
         mul++;
    else
         mul--;
    }
  chk = ((10 - (sum % 10)) % 10);
  if (chk != parseInt(s.substring(14,15),10))
    return false;
  return true;
}
		
function checkDeviceID (did){
	
	var dl = did.length;
	if(dl == 12){
		return true;
		}
	return false;	
	
	}		

function radioChecked(){

	if($("input:checked").val() !== undefined){
		return true;
		}
	return false;
	}			
$(document).ready(function() {
	

	

	
	
	$("#quote_job").change(function(){
		checkMatch();
		}); 	
	$("#ext_warranty").change(function(){
		checkMatch();
		}); 	
	$("#inv_amt1").change(function(){
		checkMatch();
		}); 
	$("#inv_amt2").change(function(){
		checkMatch();
		}); 
	$("#inv_no1").change(function(){
		checkMatch();
		}); 	
	$("#inv_no2").change(function(){
		checkMatch();
		}); 
	$("#warranty_confirm1").change(function(){
		checkMatch();
		});
	$("#warranty_confirm2").change(function(){
		checkMatch();
		}); 		 		
	$("#mobile_imei").change(function(){
		checkTheIMEI();	
			checkMatch();
		});	
	$("#mobile_aid").change(function(){
		checkTheIMEI();	
			checkMatch();
		});									
	checkMatch();
	checkTheIMEI();
	
	});
</script>
</html>
